package _01_第一季.栈与队列03;

import _01_第一季._00_公共接口.Deque;
import _01_第一季.链表02.LinkedList;

public class LinkedDeque<E> implements Deque<E> {
    private LinkedList<E> list = new LinkedList<>();
    @Override
    public int size() {
        return list.size();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    //从队尾进
    @Override
    public void enQueueRear(E element) {
        list.add(element);
    }

    //从队头出
    @Override
    public E deQueueFront() {
        return list.remove(0);
    }

    //从队头进
    @Override
    public void enQueueFront(E element) {
        list.add(0,element);
    }

    //从队尾出
    @Override
    public E deQueueRear() {
        return list.remove(list.size()-1);
    }

    @Override
    public E front() {
        return list.get(0);
    }

    @Override
    public E rear() {
        return list.get(list.size()-1);
    }

    @Override
    public void clear() {
        list.clear();
    }
}
